home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / telecomm / misc / linkz88.lha / LinkZ88 / Source / win.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-12  |  16.2 KB  |  906 lines

  1. /********************************************
  2.  **************    win.c   ******************
  3.  ********************************************/
  4.  
  5. #define INTUI_V36_NAMES_ONLY
  6.  
  7. #include <exec/exec.h>
  8. #include <intuition/intuition.h>
  9. #include <intuition/gadgetclass.h>
  10. #include <libraries/gadtools.h>
  11. #include <workbench/startup.h>
  12.  
  13. #include <clib/exec_protos.h>
  14. #include <clib/intuition_protos.h>
  15. #include <clib/gadtools_protos.h>
  16.  
  17. #include <stdlib.h>
  18. #include <string.h>
  19.  
  20. #include "windows.h"
  21.  
  22. #include "consts.h"
  23. #include "structs.h"
  24. #include "protos.h"
  25.  
  26. extern prj_p prj;
  27.  
  28. extern UWORD __chip WaitPointer[];
  29.  
  30. /*
  31. Function : BOOL win_idcmphandler(struct IntuiMessage *curr_msg)
  32. Purpose : Handles messages from the main window.
  33. */
  34.  
  35. BOOL win_idcmphandler(struct IntuiMessage *curr_msg)
  36. {
  37.     struct Gadget *gad;
  38.  
  39.     BOOL done = FALSE;
  40.  
  41.     switch (curr_msg->Class) {
  42.         case IDCMP_CLOSEWINDOW:
  43.             done = TRUE;
  44.  
  45.             break;
  46.         case IDCMP_GADGETUP:
  47.             gad = (struct Gadget *)curr_msg->IAddress;
  48.  
  49.             switch(gad->GadgetID) {
  50.                 case mainwin_listview:
  51.                     win_listview((WORD)curr_msg->Code);
  52.                     break;
  53.                 case mainwin_parent:
  54.                     win_parent();
  55.                     break;
  56.                 case mainwin_getbinary:
  57.                     win_getbinary();
  58.                     break;
  59.                 case mainwin_putbinary:
  60.                     win_putbinary();
  61.                     break;
  62.                 case mainwin_all:
  63.                     win_all();
  64.                     break;
  65.                 case mainwin_none:
  66.                     win_none();
  67.                     break;
  68.                 case mainwin_about:
  69.                     win_about();
  70.                     break;
  71.                 case mainwin_devices:
  72.                     win_devices();
  73.                     break;
  74.                 default:
  75.                     break;
  76.             }
  77.  
  78.             break;
  79.         case IDCMP_REFRESHWINDOW:
  80.             GT_BeginRefresh(mainwin);
  81.             GT_EndRefresh(mainwin,TRUE);
  82.             break;
  83.         default:
  84.             break;
  85.     }
  86.  
  87.     return (done);
  88. }
  89.  
  90. /*
  91. Function : void win_ghost_set()
  92. Purpose : Ghosts all gadgets out in window.
  93. */
  94.  
  95. void win_ghost_set()
  96. {
  97.     GT_SetGadgetAttrs(mainwinGadgets[mainwin_all],mainwin,NULL,
  98. GA_Disabled,TRUE,TAG_END);
  99.     GT_SetGadgetAttrs(mainwinGadgets[mainwin_none],mainwin,NULL,
  100. GA_Disabled,TRUE,TAG_END);
  101.     GT_SetGadgetAttrs(mainwinGadgets[mainwin_parent],mainwin,NULL,
  102. GA_Disabled,TRUE,TAG_END);
  103.     GT_SetGadgetAttrs(mainwinGadgets[mainwin_devices],mainwin,NULL,
  104. GA_Disabled,TRUE,TAG_END);
  105.  
  106.     GT_SetGadgetAttrs(mainwinGadgets[mainwin_getbinary],mainwin,NULL,
  107. GA_Disabled,TRUE,TAG_END);
  108.     GT_SetGadgetAttrs(mainwinGadgets[mainwin_putbinary],mainwin,NULL,
  109. GA_Disabled,TRUE,TAG_END);
  110.  
  111.     GT_SetGadgetAttrs(mainwinGadgets[mainwin_about],mainwin,NULL,
  112. GA_Disabled,TRUE,TAG_END);
  113. }
  114.  
  115. /*
  116. Function : void win_ghost_clear()
  117. Purpose : Unghosts all gadgets out in window.
  118. */
  119.  
  120. void win_ghost_clear()
  121. {
  122.     GT_SetGadgetAttrs(mainwinGadgets[mainwin_all],mainwin,NULL,
  123. GA_Disabled,FALSE,TAG_END);
  124.     GT_SetGadgetAttrs(mainwinGadgets[mainwin_none],mainwin,NULL,
  125. GA_Disabled,FALSE,TAG_END);
  126.     GT_SetGadgetAttrs(mainwinGadgets[mainwin_parent],mainwin,NULL,
  127. GA_Disabled,FALSE,TAG_END);
  128.     GT_SetGadgetAttrs(mainwinGadgets[mainwin_devices],mainwin,NULL,
  129. GA_Disabled,FALSE,TAG_END);
  130.  
  131.     GT_SetGadgetAttrs(mainwinGadgets[mainwin_getbinary],mainwin,NULL,
  132. GA_Disabled,FALSE,TAG_END);
  133.     GT_SetGadgetAttrs(mainwinGadgets[mainwin_putbinary],mainwin,NULL,
  134. GA_Disabled,FALSE,TAG_END);
  135.  
  136.     GT_SetGadgetAttrs(mainwinGadgets[mainwin_about],mainwin,NULL,
  137. GA_Disabled,FALSE,TAG_END);
  138. }
  139.  
  140. /*
  141. Function : void win_block_set()
  142. Purpose : Blocks the main window from input and puts up a sleep pointer.
  143. */
  144.  
  145. void win_block_set()
  146. {
  147.     if (prj->blocked)
  148.         return;
  149.  
  150.     InitRequester(&prj->req);
  151.  
  152.     if (Request(&prj->req,mainwin)) {
  153.         SetPointer(mainwin,WaitPointer,16,16,-6,0);
  154.         prj->blocked = TRUE;
  155.     }
  156. }
  157.  
  158. /*
  159. Function : void win_block_clear()
  160. Purpose : Unblocks main window.
  161. */
  162.  
  163. void win_block_clear()
  164. {
  165.     if (!prj->blocked)
  166.         return;
  167.  
  168.     ClearPointer(mainwin);
  169.     EndRequest(&prj->req,mainwin);
  170.  
  171.     prj->blocked = FALSE;
  172. }
  173.  
  174. /*
  175. Function : void win_listview(WORD num)
  176. Purpose : The user has clicked on an entry in the listview.
  177. */
  178.  
  179. void win_listview(WORD num)
  180. {
  181.     struct listviewdata *lvdata;
  182.  
  183.     /* If there's nothing in the listview */
  184.  
  185.     if (prj->zpathdepth == -1)
  186.         return;
  187.  
  188.     /* Get a quick pointer to the listviewdata */
  189.  
  190.     lvdata = prj->listviewarray[num];
  191.  
  192.     /* Are we looking at the devices ? */
  193.  
  194.     if (prj->zpathdepth == 0) {
  195.         win_ghost_set();
  196.  
  197.         /* Copy the chosen device */
  198.  
  199.         strcpy(prj->zpath,lvdata->fname);
  200.         strcat(prj->zpath,"/");
  201.  
  202.         prj->zpathdepth++;
  203.  
  204.         /* Clear the listview */
  205.  
  206.         win_listview_clear();
  207.  
  208.         /* Read the directories for the device */
  209.  
  210.         if (!serial_directories()) {
  211.             error("Unable to read directories.",
  212. ERROR_WARNING,__LINE__,__FILE__);
  213.             win_ghost_clear();
  214.  
  215.             return;
  216.         }
  217.  
  218.         /* Read the files for the device */
  219.  
  220.         if (!serial_filenames()) {
  221.             error("Unable to read filenames.",
  222. ERROR_WARNING,__LINE__,__FILE__);
  223.             win_ghost_clear();
  224.  
  225.             return;
  226.         }
  227.  
  228.         /* Redraw the listview */
  229.  
  230.         win_listview_redraw();
  231.  
  232.         win_ghost_clear();
  233.     }
  234.     else {                    /* files */
  235.         /* If clicked on dir */
  236.  
  237.         if (lvdata->zfiletype == ZFILETYPE_DIR) {
  238.             win_ghost_set();
  239.  
  240.             /* Update path */
  241.  
  242.             strcat(prj->zpath,lvdata->fname);
  243.             strcat(prj->zpath,"/");
  244.  
  245.             prj->zpathdepth++;
  246.  
  247.             /* Clear the listview */
  248.  
  249.             win_listview_clear();
  250.  
  251.             /* Read the directories for the device */
  252.  
  253.             if (!serial_directories()) {
  254.                 error("Unable to read directories.",
  255. ERROR_WARNING,__LINE__,__FILE__);
  256.                 win_ghost_clear();
  257.  
  258.                 return;
  259.             }
  260.  
  261.             /* Read the files for the device */
  262.  
  263.             if (!serial_filenames()) {
  264.                 error("Unable to read filenames.",
  265. ERROR_WARNING,__LINE__,__FILE__);
  266.                 win_ghost_clear();
  267.  
  268.                 return;
  269.             }
  270.  
  271.             /* Redraw the listview */
  272.  
  273.             win_listview_redraw();
  274.  
  275.             win_ghost_clear();
  276.         }
  277.         else {            /* clicked on file */
  278.             /* Temporarily remove the list */
  279.  
  280.             GT_SetGadgetAttrs(mainwinGadgets[mainwin_listview],
  281. mainwin,NULL,GTLV_Labels,~0,TAG_END);
  282.  
  283.             /* Toggle selected status */
  284.  
  285.             if (lvdata->text[0] == '*')
  286.                 sprintf(lvdata->text,"  %-16s",
  287. lvdata->fname);
  288.             else
  289.                 sprintf(lvdata->text,"* %-16s",
  290. lvdata->fname);
  291.  
  292.             /* Attatch list */
  293.  
  294.             GT_SetGadgetAttrs(mainwinGadgets[mainwin_listview],
  295. mainwin,NULL,GTLV_Labels,&prj->listviewlist,TAG_END);
  296.         }
  297.     }
  298. }
  299.  
  300. /*
  301. Function : void win_devices()
  302. Purpose : Gets the list of devices from the Z88.
  303. */
  304.  
  305. void win_devices()
  306. {
  307.     win_block_set();
  308.  
  309.     win_listview_clear();
  310.  
  311.     prj->zpath[0] = '\0';
  312.  
  313.     win_block_clear();
  314.     win_ghost_set();
  315.  
  316.     if (!serial_devices()) {
  317.         win_ghost_clear();
  318.  
  319.         return;
  320.     }
  321.  
  322.     prj->zpathdepth = 0;
  323.  
  324.     win_listview_redraw();
  325.  
  326.     win_ghost_clear();
  327. }
  328.  
  329. /*
  330. Function : void win_parent()
  331. Purpose : Go back to the parent directory, to the devices if neccessary.
  332. */
  333.  
  334. void win_parent()
  335. {
  336.     char *chrptr;
  337.  
  338.     /* If we're already showing the devices */
  339.  
  340.     if (!prj->zpathdepth)
  341.         return;
  342.  
  343.     /* Should we go to the devices ? */
  344.  
  345.     if (prj->zpathdepth == 1) {
  346.  
  347.         win_ghost_set();
  348.  
  349.         prj->zpath[0] = '\0';
  350.  
  351.         prj->zpathdepth = 0;
  352.  
  353.         /* Clear the listview */
  354.  
  355.         win_listview_clear();
  356.  
  357.         /* Read the devices */
  358.  
  359.         if (!serial_devices()) {
  360.             error("Unable to read devices.",ERROR_WARNING,
  361. __LINE__,__FILE__);
  362.             win_ghost_clear();
  363.  
  364.             return;
  365.         }
  366.  
  367.         /* Redraw the listview */
  368.  
  369.         win_listview_redraw();
  370.  
  371.         win_ghost_clear();
  372.     }
  373.     else {        /* step up the directory path one level */
  374.         win_ghost_set();
  375.  
  376.         /* Find penultimate directory seperator */
  377.  
  378.         for (chrptr = &prj->zpath[strlen(prj->zpath) - 2];
  379. chrptr >= prj->zpath; chrptr--) {
  380.             if (*chrptr == '/') {
  381.                 *(chrptr + 1) = '\0';
  382.  
  383.                 break;
  384.             }
  385.         }
  386.  
  387.         prj->zpathdepth--;
  388.  
  389.         /* Read the new path */
  390.  
  391.         /* Clear the listview */
  392.  
  393.         win_listview_clear();
  394.  
  395.         /* Read the directories for the device */
  396.  
  397.         if (!serial_directories()) {
  398.             error("Unable to read directories.",ERROR_WARNING,
  399. __LINE__,__FILE__);
  400.             win_ghost_clear();
  401.  
  402.             return;
  403.         }
  404.  
  405.         /* Read the files for the device */
  406.  
  407.         if (!serial_filenames()) {
  408.             error("Unable to read filenames.",ERROR_WARNING,
  409. __LINE__,__FILE__);
  410.             win_ghost_clear();
  411.  
  412.             return;
  413.         }
  414.  
  415.         /* Redraw the listview */
  416.  
  417.         win_listview_redraw();
  418.  
  419.         win_ghost_clear();
  420.     }
  421. }
  422.  
  423. /*
  424. Function : void win_getbinary()
  425. Purpose : Opens up a path requester and copies the Z88 files chosen in the
  426.     listview into the chosen Amiga directory.
  427. */
  428.  
  429. void win_getbinary()
  430. {
  431.     struct FileRequester *filereq;
  432.  
  433.     WORD l;
  434.  
  435.     BOOL found = FALSE;
  436.  
  437.     struct listviewdata *lvdata;
  438.  
  439.     win_block_set();
  440.  
  441.     /* Check that there are some Z88 files chosen */
  442.  
  443.     for (l = 0; l < MAX_LISTVIEW_ENTRIES; l++) {
  444.         lvdata = prj->listviewarray[l];
  445.  
  446.         if (!lvdata)
  447.             break;
  448.  
  449.         if (lvdata->text[0] == '*') {
  450.             found = TRUE;
  451.  
  452.             break;
  453.         }
  454.     }
  455.  
  456.     if (!found) {
  457.         error("No Z88 files selected.",ERROR_WARNING,__LINE__,__FILE__);
  458.  
  459.         win_block_clear();
  460.  
  461.         return;
  462.     }
  463.  
  464.     filereq = (struct FileRequester *)AllocAslRequestTags(
  465.         ASL_FileRequest,
  466.         ASL_Hail,"Choose dest directory...",
  467.         ASL_Dir,prj->path_binary_get,
  468.         ASL_Window,mainwin,
  469.         ASL_FuncFlags,FILF_SAVE,
  470.         ASL_ExtFlags1,FIL1F_NOFILES);
  471.  
  472.     if (!filereq) {
  473.         error("Out of memory.",ERROR_WARNING,__LINE__,__FILE__);
  474.  
  475.         win_block_clear();
  476.  
  477.         return;
  478.     }
  479.  
  480.     /* Open the requester */
  481.  
  482.     if (!AslRequest(filereq,NULL)) {
  483.         /* Cancelled */
  484.  
  485.         FreeAslRequest(filereq);
  486.  
  487.         win_block_clear();
  488.  
  489.         return;
  490.     }
  491.  
  492.     /* Clear the window block incase user wishes to abort */
  493.  
  494.     win_ghost_set();
  495.     win_block_clear();
  496.  
  497.     /* Copy path, may have changed */
  498.  
  499.     strcpy(prj->path_binary_get,filereq->rf_Dir);
  500.  
  501.     FreeAslRequest(filereq);
  502.  
  503.     /* Get selected files */
  504.  
  505.     for (l = 0; l < MAX_LISTVIEW_ENTRIES; l++) {
  506.         lvdata = prj->listviewarray[l];
  507.  
  508.         if (!lvdata)
  509.             break;
  510.  
  511.         if (lvdata->text[0] == '*') {
  512.             if (!serial_binary_get(lvdata->fname)) {
  513.                 error("Unable to get file.",ERROR_WARNING,
  514. __LINE__,__FILE__);
  515.                 win_status_clear();
  516.  
  517.                 break;
  518.             }
  519.         }
  520.     }
  521.  
  522.     win_ghost_clear();
  523. }
  524.  
  525. /*
  526. Function : void win_putbinary()
  527. Purpose : Opens a multifile requester to choose many Amiga files to send
  528.     to Z88.
  529. */
  530.  
  531. void win_putbinary()
  532. {
  533.     struct FileRequester *filereq;
  534.     struct WBArg *filereqargs;
  535.  
  536.     WORD l;
  537.  
  538.     win_block_set();
  539.  
  540.     /* Check that there is a Z88 path chosen */
  541.  
  542.     if (!prj->zpathdepth) {
  543.         error("No Z88 path selected.|"
  544. "Choose place on the Z88 to store\n"
  545. "the files from the Amiga.",ERROR_WARNING,__LINE__,__FILE__);
  546.  
  547.         win_block_clear();
  548.  
  549.         return;
  550.     }
  551.  
  552.     filereq = (struct FileRequester *)AllocAslRequestTags(
  553.         ASL_FileRequest,
  554.         ASL_Hail,"Choose source directory...",
  555.         ASL_Dir,prj->path_binary_put,
  556.         ASL_Window,mainwin,
  557.         ASL_FuncFlags,FILF_MULTISELECT | FILF_PATGAD);
  558.  
  559.     if (!filereq) {
  560.         error("Out of memory.",ERROR_WARNING,__LINE__,__FILE__);
  561.  
  562.         win_block_clear();
  563.  
  564.         return;
  565.     }
  566.  
  567.     /* Open the requester */
  568.  
  569.     if (!AslRequest(filereq,NULL)) {
  570.         /* Cancelled */
  571.  
  572.         FreeAslRequest(filereq);
  573.  
  574.         win_block_clear();
  575.  
  576.         return;
  577.     }
  578.  
  579.     /* Clear the window block incase user wishes to abort */
  580.  
  581.     win_ghost_set();
  582.     win_block_clear();
  583.  
  584.     /* Copy path, may have changed */
  585.  
  586.     strcpy(prj->path_binary_put,filereq->rf_Dir);
  587.  
  588.     /* Did the user select 1 file */
  589.  
  590.     if (!filereq->rf_NumArgs) {
  591.         if (!serial_binary_put(filereq->rf_Dir,filereq->rf_File)) {
  592.             error("Unable to put file.",ERROR_WARNING,
  593. __LINE__,__FILE__);
  594.         }
  595.  
  596.         win_status_clear();
  597.     }
  598.     else {
  599.         filereqargs = filereq->rf_ArgList;
  600.  
  601.         for (l = 0; l < filereq->rf_NumArgs; l++) {
  602.             if (!serial_binary_put(filereq->rf_Dir,
  603. filereqargs[l].wa_Name)) {
  604.                 error("Unable to put file.",ERROR_WARNING,
  605. __LINE__,__FILE__);
  606.                 win_status_clear();
  607.  
  608.                 break;
  609.             }
  610.         }
  611.     }
  612.  
  613.     FreeAslRequest(filereq);
  614.  
  615.     /* Update the directory in the listview */
  616.  
  617.     win_listview_clear();
  618.  
  619.     /* Read the directories for the device */
  620.  
  621.     if (!serial_directories()) {
  622.         error("Unable to read directories.",ERROR_WARNING,
  623. __LINE__,__FILE__);
  624.         win_ghost_clear();
  625.  
  626.         return;
  627.     }
  628.  
  629.     /* Read the files for the device */
  630.  
  631.     if (!serial_filenames()) {
  632.         error("Unable to read filenames.",ERROR_WARNING,
  633. __LINE__,__FILE__);
  634.         win_ghost_clear();
  635.  
  636.         return;
  637.     }
  638.  
  639.     /* Redraw the listview */
  640.  
  641.     win_listview_redraw();
  642.  
  643.     win_ghost_clear();
  644. }
  645.  
  646. /*
  647. Function : void win_all()
  648. Purpose : Selects all the files in the current listview.
  649. */
  650.  
  651. void win_all()
  652. {
  653.     WORD l;
  654.  
  655.     struct listviewdata *lvdata;
  656.  
  657.     win_block_set();
  658.  
  659.     /* Temporarily remove the list */
  660.  
  661.     GT_SetGadgetAttrs(mainwinGadgets[mainwin_listview],mainwin,
  662. NULL,GTLV_Labels,~0,TAG_END);
  663.  
  664.     /* Loop through all files */
  665.  
  666.     for (l = 0; l < MAX_LISTVIEW_ENTRIES; l++) {
  667.         lvdata = prj->listviewarray[l];
  668.  
  669.         if (!lvdata)
  670.             break;
  671.  
  672.         /* If it's not a file */
  673.  
  674.         if (lvdata->zfiletype != ZFILETYPE_FILE)
  675.             continue;
  676.  
  677.         /* If not selected, select it */
  678.  
  679.         if (lvdata->text[0] != '*')
  680.             sprintf(lvdata->text,"* %-16s",lvdata->fname);
  681.     }
  682.  
  683.     /* Attatch list */
  684.  
  685.     GT_SetGadgetAttrs(mainwinGadgets[mainwin_listview],mainwin,NULL,
  686. GTLV_Labels,&prj->listviewlist,TAG_END);
  687.  
  688.     win_block_clear();
  689. }
  690.  
  691. /*
  692. Function : void win_none()
  693. Purpose : Selects none of the files in the current listview.
  694. */
  695.  
  696. void win_none()
  697. {
  698.     WORD l;
  699.  
  700.     struct listviewdata *lvdata;
  701.  
  702.     win_block_set();
  703.  
  704.     /* Temporarily remove the list */
  705.  
  706.     GT_SetGadgetAttrs(mainwinGadgets[mainwin_listview],mainwin,
  707. NULL,GTLV_Labels,~0,TAG_END);
  708.  
  709.     /* Loop through all files */
  710.  
  711.     for (l = 0; l < MAX_LISTVIEW_ENTRIES; l++) {
  712.         lvdata = prj->listviewarray[l];
  713.  
  714.         if (!lvdata)
  715.             break;
  716.  
  717.         /* If it's not a file */
  718.  
  719.         if (lvdata->zfiletype != ZFILETYPE_FILE)
  720.             continue;
  721.  
  722.         /* If not selected, select it */
  723.  
  724.         if (lvdata->text[0] == '*')
  725.             sprintf(lvdata->text,"  %-16s",lvdata->fname);
  726.     }
  727.  
  728.     /* Attatch list */
  729.  
  730.     GT_SetGadgetAttrs(mainwinGadgets[mainwin_listview],mainwin,NULL,
  731. GTLV_Labels,&prj->listviewlist,TAG_END);
  732.  
  733.     win_block_clear();
  734. }
  735.  
  736. /*
  737. Function : void win_about()
  738. Purpose : Pops up an about requester.
  739. */
  740.  
  741. void win_about()
  742. {
  743.     error(VERSION_NAME"\n"
  744. "Version : "VERSION_NUMBER"\n"
  745. "Date    : "VERSION_DATE,ERROR_WARNING,__LINE__,__FILE__);
  746. }
  747.  
  748. /*
  749. Function : void win_status_set(char *text)
  750. Purpose : Puts the given text into the status window.
  751. */
  752.  
  753. void win_status_set(char *text)
  754. {
  755.     static char status_text[STRLEN_STATUS];
  756.  
  757.     /* Copy the text to the buffer */
  758.  
  759.     strcpy(status_text,text);
  760.  
  761.     /* Put the text in the gadget */
  762.  
  763.     GT_SetGadgetAttrs(mainwinGadgets[mainwin_status],mainwin,NULL,
  764. GTTX_Text,status_text,TAG_END);
  765. }
  766.  
  767. /*
  768. Function : void win_status_clear()
  769. Purpose : Puts up a default string in the status bar.
  770. */
  771.  
  772. void win_status_clear()
  773. {
  774.     GT_SetGadgetAttrs(mainwinGadgets[mainwin_status],mainwin,NULL,
  775. GTTX_Text,"",TAG_END);
  776. }
  777.  
  778. /*
  779. Function : void win_listview_clear()
  780. Purpose : Frees all the memory in the prj->listviewarray and resets the
  781.     prj->listviewlist. Clears the listview display.
  782. */
  783.  
  784. void win_listview_clear()
  785. {
  786.     WORD l;
  787.  
  788.     /* Clear display */
  789.  
  790.     GT_SetGadgetAttrs(mainwinGadgets[mainwin_listview],mainwin,NULL,
  791. GTLV_Labels,NULL,TAG_END);
  792.  
  793.     /* Reset list */
  794.  
  795.     NewList(&prj->listviewlist);
  796.  
  797.     /* Free mem */
  798.  
  799.     for (l = 0; l < MAX_LISTVIEW_ENTRIES; l++) {
  800.         if (prj->listviewarray[l])
  801.             free(prj->listviewarray[l]);
  802.  
  803.         prj->listviewarray[l] = NULL;
  804.     }
  805. }
  806.  
  807. /*
  808. Function : BOOL win_listview_add(struct listviewdata *data,
  809.     zfiletype_e zfiletype)
  810. Purpose : Copies the data given in 'data' and places it in the next free
  811.     entry of the prj->listviewarray. Add the entry to the
  812.     prj->listviewlist. The filetype (file, dev or dir) is given in
  813.     'zfiletype'. Returns TRUE on success, FALSE if out of memory or
  814.     no room left in array.
  815. */
  816.  
  817. BOOL win_listview_add(struct listviewdata *data,zfiletype_e zfiletype)
  818. {
  819.     WORD l;
  820.  
  821.     struct listviewdata *new_data;
  822.  
  823.     char typestring[10];
  824.  
  825.     /* Check that we're not adding an invalid entry */
  826.  
  827.     if ((zfiletype == ZFILETYPE_DEV) && (strchr(data->fname,'-')))
  828.         return (TRUE);
  829.  
  830.     if ((zfiletype == ZFILETYPE_DIR) && (!strcmp(data->fname,".")))
  831.         return (TRUE);
  832.  
  833.     if ((zfiletype == ZFILETYPE_DIR) && (!strcmp(data->fname,"..")))
  834.         return (TRUE);
  835.  
  836.     /* Allocate new listviewdata */
  837.  
  838.     new_data = malloc(sizeof(struct listviewdata));
  839.  
  840.     if (!new_data)
  841.         return (FALSE);
  842.  
  843.     /* Copy the data */
  844.  
  845.     CopyMem(data,new_data,sizeof(struct listviewdata));
  846.  
  847.     /* Set up list part */
  848.  
  849.     AddTail(&prj->listviewlist,(struct Node *)new_data);
  850.  
  851.     new_data->node.ln_Name = new_data->text;
  852.  
  853.     /* Setup the other data */
  854.  
  855.     new_data->zfiletype = zfiletype;
  856.  
  857.     switch (zfiletype) {
  858.         case ZFILETYPE_DEV:
  859.             strcpy(typestring,"[dev]");
  860.             break;
  861.         case ZFILETYPE_DIR:
  862.             strcpy(typestring,"[dir]");
  863.             break;
  864.         case ZFILETYPE_FILE:
  865.             strcpy(typestring,"");
  866.             break;
  867.         default:
  868.             error("Unknown ZFILETYPE.",ERROR_INTERNAL,
  869. __LINE__,__FILE__);
  870.             break;
  871.     }
  872.  
  873.     sprintf(new_data->text,"  %-16s %s",new_data->fname,typestring);
  874.  
  875.     /* Add to array */
  876.  
  877.     for (l = 0; l < MAX_LISTVIEW_ENTRIES; l++) {
  878.         if (!prj->listviewarray[l]) {
  879.             prj->listviewarray[l] = new_data;
  880.  
  881.             break;
  882.         }
  883.     }
  884.  
  885.     /* If no space in array */
  886.  
  887.     if (l == MAX_LISTVIEW_ENTRIES)
  888.         return (FALSE);
  889.  
  890.     /* Return OK */
  891.  
  892.     return (TRUE);
  893. }
  894.  
  895. /*
  896. Function : void win_listview_redraw()
  897. Purpose : Redraws the list in the listview.
  898. */
  899.  
  900. void win_listview_redraw()
  901. {
  902.     GT_SetGadgetAttrs(mainwinGadgets[mainwin_listview],mainwin,NULL,
  903. GTLV_Labels,&prj->listviewlist,TAG_END);
  904. }
  905.  
  906.